home *** CD-ROM | disk | FTP | other *** search
- unit Mpdu2;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls, TabNotBk;
-
- type
- TForm1 = class(TForm)
- PagesGrp: TRadioGroup;
- PresentChk: TCheckBox;
- procedure PresentChkClick(Sender: TObject);
- private
- procedure HidePage(Notebook: TTabbedNotebook; PageNum: Word;
- Hide: Boolean);
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- MPDU1;
-
- {$R *.DFM}
-
- procedure TForm1.HidePage(Notebook: TTabbedNotebook; PageNum: Word;
- Hide: Boolean);
- const
- Proxy: TTabPage = nil;
- ProxyName: String = '';
- var
- Page: TTabPage;
- begin
- if Hide then
- begin
- { Can't assign new value to Pages.Objects[i] as it's }
- { implemented as the base TStrings no-op, meaning }
- { the real page will be deleted, losing child controls }
- { Also, Assign is not implemented }
- { Make surrogate parent window instead }
- Proxy := TTabPage.Create(Self);
- Page := Notebook.Pages.Objects[PageNum] as TTabPage;
- { Save page name }
- ProxyName := Page.Caption;
- { Transfer all page children to foster parent }
- while Page.ControlCount > 0 do
- Page.Controls[0].Parent := Proxy;
- { Delete target page }
- Notebook.Pages.Delete(PageNum);
- end
- else
- begin
- { Stop bad flicker as page is inserted }
- Notebook.Hide;
- { Can't use InsertObject - doesn't work }
- { Use Insert, which makes the TTabPage object }
- Notebook.Pages.Insert(PageNum, ProxyName);
- { Avoid tab-button refocus problem (caused by page }
- { being inserted where PageIndex is currently set) }
- { by moving PageIndex one left, then moving one }
- { right (catering for already being at the beginning }
- { - the right hand side of the addition resolves to ▒1) }
- Notebook.PageIndex := Notebook.PageIndex + (Byte(PageNum = 0) * 2) - 1;
- Notebook.PageIndex := Notebook.PageIndex + (Byte(PageNum > 0) * 2) - 1;
- Page := Notebook.Pages.Objects[PageNum] as TTabPage;
- { Move children back to natural parent }
- while Proxy.ControlCount > 0 do
- Proxy.Controls[0].Parent := Page;
- { Destroy foster parent }
- Proxy.Free;
- Notebook.Show;
- end;
- end;
-
- procedure TForm1.PresentChkClick(Sender: TObject);
- begin
- PagesGrp.Enabled := PresentChk.Checked;
- HidePage(Form2.Notebook, PagesGrp.ItemIndex, not PresentChk.Checked);
- end;
-
- end.
-